<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">来源</label>
                        <div class="layui-input-block">
                            <select id="table" name="table" lay-filter="table">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">附件类别</label>
                        <div class="layui-input-block">
                            <input type="text" name="typename" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">文件名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">创建人</label>
                        <div class="layui-input-block">
                            <input type="text" name="realname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="muid" name="muid">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="layui-card" id="table-card">
    <div class="layui-card-body" id="listfold">
        <div class="layui-row">
            <?php include 'dao.php' ?>
            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>
    var param_enginid = getQueryVariable('enginid') || 0;


    var EnginViewerObj;
    function upload_engin_files_file_viewer(dom='listfold'){
        try {
            EnginViewerObj.destroy();
        }catch (e) {

        }
        EnginViewerObj = new Viewer(document.getElementById('listfold'));
    }
    function upload_engin_fold_files_viewer_img_show(index=0){
        EnginViewerObj.view(index);
    }


    var currButAuth, currTabData, fileArrs,filenum=0;;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        var height_l = $('.laytp-container').height() - 140;
        $('#tree_content').css('cssText','height:'+height_l+'px');
        $('.engindao_bac').css('cssText','height:'+height_l+'px');

        setSouTableExport('项目资料信息');
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_engin_fold_list)
            ,where: {enginid:param_enginid}
            , page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response
            ,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xiala_zhan_one_zuo('table', res.data.table, res.data.is_table);

                fileArrs = [];
                filenum = 0;

                $(".quanbu").text(res.data.enginname)

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'tablename', title: '来源'}
                ,{field: 'typename', title: '附件类别'}
                ,{field:'name',title:'文件名称',templet: function (d) {
                    if(d.ext == 'png' || d.ext == 'pneg' || d.ext == 'jpg' || d.ext == 'jpeg' || d.ext == 'gif'){
                        fileArrs[d.id] = filenum;
                        filenum++;
                        return '<span>'+d.name+'</span><img src="'+get_engin_fold_file_complete(d.encpath)+'" style="display: none">';
                    }else{
                        return '<span>'+d.name+'</span>';
                    }
                }}
                ,{field: 'ext', title: '文件格式'}
                ,{field: 'size', title: '文件大小'}
                ,{field: 'created_user_name', title: '创建人'}
                ,{field: 'created_at', title: '创建时间'}
                ,{field: 'muid_name', title: '所在文件夹'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
                upload_engin_files_file_viewer();
            }
        });

        listTableSearch(form, table);

    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        var fileext = trData.ext;
        var fileurl = get_engin_fold_file_complete(trData.encpath);
        if(fileext == 'png' || fileext == 'pneg' || fileext == 'jpg' || fileext == 'jpeg' || fileext == 'gif'){
            upload_engin_fold_files_viewer_img_show(fileArrs[trData.id]);
        }else if(fileext == 'pdf'){
            upload_files_viewer_pdf_show(fileurl);
        }else if(fileext == 'doc' || fileext == 'docx' || fileext == 'xls' || fileext == 'xlsx' || fileext == 'ppt' || fileext == 'pptx'){
            upload_files_vieweroffice_show(fileurl);
        }else{
            facade.error("此文件类型不支持预览,请下载查看");
        }
    }
    function auth_but_func_chuan(){
        var muid = $("#muid").val() || 0;
        if(!muid){
            facade.error("请先选择要上传的文件夹");return false;
        }

        layui.use('layer',function(){
            var layer = layui.layer;
            layer.open({
                type: 2,
                title: '上传文件',
                maxmin: true,
                area: ['770px', '490px'],
                content: 'chuan.php?enginid='+param_enginid+'&muid='+muid,
                cancel :function (index) {
                    layer.confirm("正在上传文件信息，是否直接关闭窗口？",function (conindex) {
                        layui.table.reload('datalist');
                        layer.close(conindex);
                        layer.close(index);
                    });
                    return false;
                }
            });
        });
    }
    function auth_but_func_zhuan(buttitle){
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        openPageEdit('zhuan.php?close=1&ids='+idArr.join(','), '770px', '490px');
    }
    function auth_but_func_down(buttitle, index){
        var trData = currTabData[index];
        public_down_engin_fold_file(trData.encpath)
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        layer.confirm("<div class='tit'>是否确认删除？</div><div class='exp'>删除后，可至回收站查看。</div>", {
                title:'操作确认',
                icon: 3,
                area:['450px','220px'],
                btn:['确定']
            }, function(conindex){
                facade.ajax({url: ask_engin_fold_del, data:{id:trData.id, type:1}}).done(function(res){
                    if (res.code === 2000) {
                        facade.success("提交成功!");
                        try {
                            layui.table.reload('datalist');
                            layui.use(['table','form'], function () {
                                var table = layui.table,form = layui.form;
                                searchTableFunc(form, table);
                            })
                        }catch (e) {

                        }
                        layer.close(conindex);
                    }
                });
            }
        )
    }
    function auth_but_func_shou(buttitle, index){
        openNavPage(buttitle,'engin_fold/shou.php?enginid='+param_enginid);
    }
















    function opt_tree(data, status) {
        for (var i=0;i<data.length;i++){
            data[i]['spread'] = status;
            if(data[i].children != undefined){
                opt_tree(data[i].children, status);
            }
        }
        return data;
    }
</script>
</body>
</html>
